*************************************
*** Panel Analysis: BHPS *************
*************************************

clear
global OUT "SET_YOUR_OUTPATH"

// this is for data which is later read into R
global OUT2 "SET_YOUR_OUTPATH_FOR_DATAFRAMES"	


*create dummy datasets for regsave

*hybrid models
clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_sat.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_loginc.dta", replace


*bivariate
clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_0.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt_0.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_sat_0.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_loginc_0.dta", replace


*equivalence testing
clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt_e.dta", replace





* fe lag models
clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_hhinc.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_hhinc_dec_pp_sqrt.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_hhinc_sat.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_loginc.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_incdiff2.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_jobloss.dta", replace

clear
input coef stderr ci_lower ci_upper N _id
. . . . . .
end
save "$OUT2\BHPS\bhps_coef_lag_inc_subj_obj.dta", replace







*load data
use "SET_YOUR_INPATH\BHPS\combined\bhps_ukhls_long.dta", clear


*relevant variables:
*sep: fihhmngrs_dv (gross hh inc, month), fiyr (annual pers. inc.), lfsat2 sclfsat2 (sat. w. hh inc)
	* satfin (sat. w. fin. sit)
*pol. vars: 
	*interest: vote6
	*vote: vote1 (supp. pol. party) vote3 (next election), vote7 (last election), voteintent (intention to vote, only UKHLS)
	*perpolinf demorient (sat. dem.), poleff1 poleff2 (int. eff.), poleff3 poleff4 (ext. eff.)
*socdem: hhsize (num. pers. in hh), age, sex, jbstat (empstat), hiqualb_dv
*ids: pidp wave 



xtset pidp wave

fre lfsat2 satfin sclfsat2
fre hhsize age sex jbstat hiqualb_dv
fre vote6 vote1 vote3 vote7 voteintent
*ids: pidp wave


*remove outliers
replace hhinc=. if hhinc<0 | hhinc>30000

*use hhinc with standardized hhinc
egen zhhinc = std(hhinc)
replace hhinc = zhhinc

*** recode variables

// use income deciles from 1-10
rename hhinc_dec10 hhinc_dec10_
clonevar hhinc_dec10 = hhinc_dec 
 
rename hhinc_dec_pp10 hhinc_dec_pp10_
clonevar hhinc_dec_pp10 = hhinc_dec_pp 
 
rename hhinc_dec_pp_sqrt10 hhinc_dec_pp_sqrt10_
clonevar hhinc_dec_pp_sqrt10 = hhinc_dec_pp_sqrt 
 

 // create log eqhhinc
gen loginc = ln(hhinc_pp_sqrt)

*create interaction variables
gen hhincXage = hhinc * age18
gen hhinc_ppXage = hhinc_pp * age18
gen hhinc_pp_sqrtXage = hhinc_pp_sqrt * age18

gen hhinc_decXage = hhinc_dec10 * age18
gen hhinc_dec_ppXage = hhinc_dec_pp10 * age18
gen hhinc_dec_pp_sqrtXage = hhinc_dec_pp_sqrt10 * age18

gen hhinc_satXage = hhinc_sat10 * age18

gen hhinc_decXage1835 = hhinc_dec10 * age1835
gen hhinc_satXage1835 = hhinc_sat10 * age1835


* generate income change/jobloss variables

gen incdiff = hhinc_dec-L.hhinc_dec 

recode incdiff (-9/-1=1 "shock")(0/9=0 "no shock")(else=.), gen(incdiff1)
recode incdiff (-9/-2=1 "shock")(-1 0/9=0 "no shock")(else=.), gen(incdiff2)

gen hhinc_dec_t1 = L.hhinc_dec  

gen incdiff_cat = .
replace incdiff_cat = 0 if incdiff==0
replace incdiff_cat = 1 if incdiff>0
replace incdiff_cat = 2 if incdiff==-1
replace incdiff_cat = 3 if incdiff<=-2 & hhinc_dec_t1>=5
replace incdiff_cat = 4 if incdiff<=-2 & hhinc_dec_t1==4
replace incdiff_cat = 5 if incdiff<=-2 & hhinc_dec_t1==3

lab def incdiff_cat 0 "no change" 1 "increase (any)" 2 "1 decile drop (any)" ///
	3 "2 decile drop (t-1: decile 5 or higher)" ///
	4 "2 decile drop (t-1: decile 4)" ///
	5 "2 decile drop (t-1: decile 3)" 
lab val incdiff_cat incdiff_cat
	
recode incdiff_cat (1=1 "increase")(0 2/5=0)(else=.), gen(idc1)
recode incdiff_cat (2=1 "1 decile drop")(0 1 3/5=0)(else=.), gen(idc2)
recode incdiff_cat (3=1 "2 decile drop (t-1: decile 5 or higher)")(0 1 2 4 5=0)(else=.), gen(idc3)
recode incdiff_cat (4=1 "2 decile drop (t-1: decile 4)")(0/3 5=0)(else=.), gen(idc4)
recode incdiff_cat (5=1 "2 decile drop (t-1: decile 3)")(0/4=0)(else=.), gen(idc5)

// jobloss has 5609 cases on 1
gen jobloss = 0
replace jobloss = . if jbstat==.
replace jobloss = 1 if jbstat==3 & (L.jbstat==1 | L.jbstat==2)


// controlling for PI in t-2
gen polint_t2 = L2.polint
gen pit2Xshock = polint_t2 * incdiff2
gen pit2Xhhinc = polint_t2 * hhinc_dec_pp_sqrt10


*create engagement scales via factor analysis
reg polint polsup
gen mysample1 = e(sample)
polychoric polint polsup if mysample1==1

global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1)
predict f1
sum f1
gen engagement = ((f1 - r(min)) / (r(max)-r(min)))*10


*labels
lab var polint10 "Pol. Interest"
lab var polsup "Vote"
lab var inteff10 "Int. Efficacy"
lab var voteintent10 "Intention to vote"
lab var voteduty10 "Duty to vote"
lab var vote_persben10 "Vote pers. ben."
lab var engagement "Political Engagement Scale"







**************************************
***** Analysis ***********************
**************************************

estpost summarize polint10 polsup inteff10 exeff10 voteintent10 votemdiff10 voteduty10 vote_persben10 vote_grpben10 ///
	hhinc_pp_sqrt hhinc_dec_pp_sqrt10 hhinc_sat10 female age18 unemployed nlf edu_med edu_high migrant  incdiff2 jobloss hhinc_decXage hhinc_satXage  ///
	hhinc_dec_ppXage hhinc_dec_pp_sqrtXage
 esttab using "$OUT\Tables\BHPS\summary_stats_bhps.rtf", cells("count mean(fmt(3)) sd(fmt(3))  min max") replace

 estpost summarize polint10 polsup inteff10 exeff10 voteintent10 votemdiff10 voteduty10 vote_persben10 vote_grpben10 ///
	hhinc_pp_sqrt hhinc_dec_pp_sqrt10 hhinc_sat10 female age18 unemployed nlf edu_med edu_high migrant  incdiff2 jobloss hhinc_decXage hhinc_satXage  ///
	hhinc_dec_ppXage hhinc_dec_pp_sqrtXage
 esttab using "$OUT\Tables\BHPS\summary_stats_bhps.tex", cells("count mean(fmt(3)) sd(fmt(3))  min max") replace


* regressions with age (continuous)

// for coef export
foreach var of varlist polint10 polsup inteff10 voteintent10 voteduty10 vote_persben10  {
	xthybrid `var' hhinc, clusterid(pidp) full
	eststo m001_`var'
	regsave W__hhinc B__hhinc using "$OUT2\BHPS\bhps_coef_hhinc_0.dta", ci level(95) autoid append
	xthybrid `var' hhinc female age18 unemployed nlf edu_med edu_high migrant, clusterid(pidp) full
	eststo m01_`var'
	regsave W__hhinc B__hhinc using "$OUT2\BHPS\bhps_coef_hhinc.dta", ci level(95) autoid append
	
	xthybrid `var' loginc, clusterid(pidp) full
	eststo m002_`var'
	regsave W__loginc B__loginc using "$OUT2\BHPS\bhps_coef_loginc_0.dta", ci level(95) autoid append
	xthybrid `var' loginc female age18 unemployed nlf edu_med edu_high migrant, clusterid(pidp) full
	eststo m02_`var'
	regsave W__loginc B__loginc using "$OUT2\BHPS\bhps_coef_loginc.dta", ci level(95) autoid append
	
	
	xthybrid `var' hhinc_dec_pp_sqrt10, clusterid(pidp) full
	eststo m03_`var'
	regsave W__hhinc_dec_pp_sqrt10 B__hhinc_dec_pp_sqrt10 using "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt_0.dta", ci level(95) autoid append
	xthybrid `var' hhinc_dec_pp_sqrt10 female age18 unemployed nlf edu_med edu_high migrant, clusterid(pidp) full
	eststo m3_`var'
	regsave W__hhinc_dec_pp_sqrt10 B__hhinc_dec_pp_sqrt10 using "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt.dta", ci level(95) autoid append
	
	xthybrid `var' hhinc_sat10, clusterid(pidp) full
	eststo m04_`var'
	regsave W__hhinc_sat10 B__hhinc_sat10 using "$OUT2\BHPS\bhps_coef_hhinc_sat_0.dta", ci level(95) autoid append
	xthybrid `var' hhinc_sat10 female age18 unemployed nlf edu_med edu_high  migrant, clusterid(pidp) full
	eststo m4_`var'
	regsave W__hhinc_sat10 B__hhinc_sat10 using "$OUT2\BHPS\bhps_coef_hhinc_sat.dta", ci level(95) autoid append
}

// for equivalence testing
foreach var of varlist polint10 polsup inteff10 voteintent10 voteduty10 vote_persben10  {
	xtreg `var' hhinc_dec_pp_sqrt10 age18 unemployed nlf edu_med edu_high, fe
	regsave hhinc_dec_pp_sqrt10 using "$OUT2\BHPS\bhps_coef_hhinc_dec_pp_sqrt_e.dta", ci level(90) autoid append
}	



// interactions
foreach var of varlist polint10 polsup inteff10 voteintent10 voteduty10 vote_persben10 {
	xthybrid `var' hhinc_dec_pp_sqrt10 female age18 unemployed nlf edu_med edu_high migrant hhinc_dec_pp_sqrtXage, clusterid(pidp) full
	eststo m7_`var'
}

// two tables
esttab m3_polint10 m7_polint10 m3_polsup m7_polsup m3_inteff10 m7_inteff10 ///
	m3_voteintent10 m7_voteintent10 m3_voteduty10 m7_voteduty10 ///
	m3_vote_persben10 m7_vote_persben10 ///
	using "$OUT\Tables\BHPS\hybrid_all_incdec_pp_sqrt.rtf", b(3) se replace
esttab m3_polint10 m7_polint10 m3_polsup m7_polsup m3_inteff10 m7_inteff10 ///
	m3_voteintent10 m7_voteintent10 m3_voteduty10 m7_voteduty10 ///
	m3_vote_persben10 m7_vote_persben10 ///
	using "$OUT\Tables\BHPS\hybrid_all_incdec_pp_sqrt.tex", b(3) se replace label nonumbers booktabs alignment(D{.}{.}{3}) scalars("N N")	///
	varlabels ///
				(R__sex "Sex" ///
				R__migrant "Migrant" ///
				R__edu_med "Edu: medium" ///
				R__edu_high "Edu: high" ///
				W__edu_med "W: Edu: medium" ///
				W__edu_high "W: Edu: high" ///
				B__edu_med "B: Edu: medium" ///
				B__edu_high "B: Edu: high" ///
				W__age18 "W: Age" ///
				B__age18 "B: Age" ///
				W__unemployed "W: Unemployed" ///
				B__unemployed "B: Unemployed" ///
				W__nlf "W: Not in Labor Force" ///
				B__nlf "B: Not in Labor Force" ///
				W__hhinc "W: Income" ///
				B__hhinc "B: Income" ///
				W__hhincXage "W: Inc. * Age" ///
				B__hhincXage "B: Inc. * Age" ///
				W__hhinc_dec_pp_sqrt10 "W: Income (dec.)" ///
				B__hhinc_dec_pp_sqrt10 "B: Income (dec.)" ///
				W__hhinc_dec_pp_sqrtXage "W: Inc. (dec.) * Age" ///
				B__hhinc_dec_pp_sqrtXage "B: Inc. (dec.) * Age" ///
				W__hhinc_sat "W: Sat. Income" ///
				B__hhinc_sat "B: Sat. Income" ///
				W__hhinc_satXage "W: Sat. Inc. * Age" ///
				B__hhinc_satXage "B: Sat. Inc. * Age" ///
				_cons "Constant")	    


// engagement scale:
xthybrid engagement hhinc_dec_pp_sqrt10 female age18 unemployed nlf edu_med edu_high migrant, clusterid(pidp) full  
eststo m_engage	

esttab m_engage ///
	using "$OUT\Tables\BHPS\hybrid_engage_eqinc.tex", b(3) se replace label nonumbers booktabs alignment(D{.}{.}{3}) scalars("N N")	///
	varlabels ///
				(R__female "Sex" ///
				R__migrant "Migrant" ///
				R__edu_med "Edu: medium" ///
				R__edu_high "Edu: high" ///
				W__edu_med "Edu: medium" ///
				W__edu_high "Edu: high" ///
				B__edu_med "Edu: medium" ///
				B__edu_high "Edu: high" ///
				W__age18 "W: Age" ///
				B__age18 "B: Age" ///
				W__unemployed "W: Unemployed" ///
				B__unemployed "B: Unemployed" ///
				W__nlf "W: Not in Labor Force" ///
				B__nlf "B: Not in Labor Force" ///
				W__hhinc_dec_pp_sqrt10 "W: Income (dec.)" ///
				B__hhinc_dec_pp_sqrt10 "B: Income (dec.)" ///
				_cons "Constant")				
				
				
				

// test: objective income on subjective income
foreach var of varlist hhinc hhinc_dec_pp_sqrt10 incdiff2 {
	xthybrid hhinc_sat `var' female age18 unemployed nlf edu_med edu_high migrant , clusterid(pidp) full
	eststo inc_so_`var'
}
esttab inc_so_hhinc inc_so_hhinc_dec_pp_sqrt10 inc_so_incdiff2 ///
	using "$OUT\Tables\BHPS\hybrid_all_inc_subj_obj.rtf", b(2) se replace
esttab inc_so_hhinc inc_so_hhinc_dec_pp_sqrt10 inc_so_incdiff2 ///
	using "$OUT\Tables\BHPS\hybrid_all_inc_subj_obj.tex", b(2) se replace label nonumber booktabs alignment(D{.}{.}{2})       


	
	
*logistic model for polsup	
xthybrid polsup hhinc_dec_pp_sqrt10 female age18 unemployed nlf edu_med edu_high migrant, clusterid(pidp) family(binomial) link(logit) full
eststo m1_polsup_logit

esttab m1_polsup_logit  using "$OUT\Tables\BHPS\hybrid_polsup_logit.rtf", b(3) se replace
esttab m1_polsup_logit  using "$OUT\Tables\BHPS\hybrid_polsup_logit.tex", b(3) se replace label nonumbers booktabs alignment(D{.}{.}{3}) scalars("N N")	///
	varlabels ///
				(R__sex "Sex" ///
				R__migrant "Migrant" ///
				R__edu_med "Edu: medium" ///
				R__edu_high "Edu: high" ///
				W__edu_med "W: Edu: medium" ///
				W__edu_high "W: Edu: high" ///
				B__edu_med "B: Edu: medium" ///
				B__edu_high "B: Edu: high" ///
				W__age18 "W: Age" ///
				B__age18 "B: Age" ///
				W__unemployed "W: Unemployed" ///
				B__unemployed "B: Unemployed" ///
				W__nlf "W: Not in Labor Force" ///
				B__nlf "B: Not in Labor Force" ///
				W__hhinc "W: Income" ///
				B__hhinc "B: Income" ///
				W__hhincXage "W: Inc. * Age" ///
				B__hhincXage "B: Inc. * Age" ///
				W__hhinc_dec_pp_sqrt10 "W: Income (dec.)" ///
				B__hhinc_dec_pp_sqrt10 "B: Income (dec.)" ///
				W__hhinc_dec_pp_sqrtXage "W: Inc. (dec.) * Age" ///
				B__hhinc_dec_pp_sqrtXage "B: Inc. (dec.) * Age" ///
				W__hhinc_sat "W: Sat. Income" ///
				B__hhinc_sat "B: Sat. Income" ///
				W__hhinc_satXage "W: Sat. Inc. * Age" ///
				B__hhinc_satXage "B: Sat. Inc. * Age" ///
				_cons "Constant")	    



*************************
* FE models
*************************

* restriction: variables need to be at least in 4 waves


* FE model
foreach var of varlist polsup polint10 {
	xtreg `var' L(0/3).hhinc F1.hhinc age18 unemployed nlf edu_med edu_high, fe
	eststo fe0_`var'_inc
	regsave F1.hhinc hhinc L1.hhinc L2.hhinc L3.hhinc using "$OUT2\BHPS\bhps_coef_lag_hhinc.dta", ci level(95) autoid append
	xtreg `var' L(0/3).loginc F1.loginc age18 unemployed nlf edu_med edu_high, fe
	eststo fe0_`var'_loginc
	regsave F1.loginc loginc L1.loginc L2.loginc L3.loginc using "$OUT2\BHPS\bhps_coef_lag_loginc.dta", ci level(95) autoid append
	xtreg `var' L(0/3).hhinc_dec_pp_sqrt10 F1.hhinc_dec_pp_sqrt10 age18 unemployed nlf edu_med edu_high, fe
	eststo fe_`var'_inc_pp_s
	regsave F1.hhinc_dec_pp_sqrt10 hhinc_dec_pp_sqrt10 L1.hhinc_dec_pp_sqrt10 L2.hhinc_dec_pp_sqrt10 L3.hhinc_dec_pp_sqrt10 using "$OUT2\BHPS\bhps_coef_lag_hhinc_dec_pp_sqrt.dta", ci level(95) autoid append
	xtreg `var' L(0/3).hhinc_sat10 F1.hhinc_sat10 age18 unemployed nlf edu_med edu_high, fe
	eststo fe_`var'_inc_sat
	regsave F1.hhinc_sat10 hhinc_sat10 L1.hhinc_sat10 L2.hhinc_sat10 L3.hhinc_sat10 using "$OUT2\BHPS\bhps_coef_lag_hhinc_sat.dta", ci level(95) autoid append
	xtreg `var' L(0/3).incdiff2 F1.incdiff2 age18 unemployed nlf edu_med edu_high, fe
	eststo fe_`var'_incdiff2
	regsave F1.incdiff2 incdiff2 L1.incdiff2 L2.incdiff2 L3.incdiff2 using "$OUT2\BHPS\bhps_coef_lag_incdiff2.dta", ci level(95) autoid append
	xtreg `var' L(0/3).jobloss F1.jobloss age18 edu_med edu_high, fe
	eststo fe_`var'_jobloss
	*regsave F1.jobloss jobloss L1.jobloss L2.jobloss L3.jobloss using "$OUT2\BHPS\bhps_coef_lag_jobloss.dta", ci level(95) autoid append
}

	
esttab fe_polsup_incdiff2 fe_polint10_incdiff2 ///
	using "$OUT\Tables\BHPS\fe_lag_all_incdiff2.rtf", b(3) se replace	
esttab fe_polsup_incdiff2 fe_polint10_incdiff2 ///
	using "$OUT\Tables\BHPS\fe_lag_all_incdiff2.tex", b(3) scalars("N N") se replace label nonumbers booktabs alignment(D{.}{.}{3})	///
	varlabels ///
				(edu_med "Edu: medium" ///
				edu_high "Edu: high" ///
				age18 "Age" ///
				unemployed "Unemployed" ///
				nlf "Not in Labor Force" ///
				hhinc "Income\textsubscript{t0}" ///
				L.hhinc "Income\textsubscript{t-1}" ///
				L2.hhinc "Income\textsubscript{t-2}" ///
				L3.hhinc "Income\textsubscript{t-3}" ///
				F.hhinc "Income\textsubscript{t+1}" ///
				hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t0}" ///
				L.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-1}" ///
				L2.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-2}" ///
				L3.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-3}" ///
				F.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t+1}" ///
				hhinc_sat "Sat. Income\textsubscript{t0}" ///
				L.hhinc_sat "Sat. Income\textsubscript{t-1}" ///
				L2.hhinc_sat "Sat. Income\textsubscript{t-2}" ///
				L3.hhinc_sat "Sat. Income\textsubscript{t-3}" ///
				F.hhinc_sat "Sat. Income\textsubscript{t+1}" ///
				incdiff2 "Inc. Shock\textsubscript{t0}" ///
				L.incdiff2 "Inc. Shock\textsubscript{t-1}" ///
				L2.incdiff2 "Inc. Shock\textsubscript{t-2}" ///
				L3.incdiff2 "Inc. Shock\textsubscript{t-3}" ///
				F.incdiff2 "Inc. Shock\textsubscript{t+1}" ///
				_cons "Constant")      
	
esttab fe_polsup_jobloss fe_polint10_jobloss ///
	using "$OUT\Tables\BHPS\fe_lag_all_jobloss.rtf", b(3) se replace		
esttab fe_polsup_jobloss fe_polint10_jobloss ///
	using "$OUT\Tables\BHPS\fe_lag_all_jobloss.tex", b(3) scalars("N N") se replace label nonumbers booktabs alignment(D{.}{.}{3})	///
	varlabels ///
				(edu_med "Edu: medium" ///
				edu_high "Edu: high" ///
				age18 "Age" ///
				unemployed "Unemployed" ///
				nlf "Not in Labor Force" ///
				hhinc "Income\textsubscript{t0}" ///
				L.hhinc "Income\textsubscript{t-1}" ///
				L2.hhinc "Income\textsubscript{t-2}" ///
				L3.hhinc "Income\textsubscript{t-3}" ///
				F.hhinc "Income\textsubscript{t+1}" ///
				hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t0}" ///
				L.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-1}" ///
				L2.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-2}" ///
				L3.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-3}" ///
				F.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t+1}" ///
				hhinc_sat "Sat. Income\textsubscript{t0}" ///
				L.hhinc_sat "Sat. Income\textsubscript{t-1}" ///
				L2.hhinc_sat "Sat. Income\textsubscript{t-2}" ///
				L3.hhinc_sat "Sat. Income\textsubscript{t-3}" ///
				F.hhinc_sat "Sat. Income\textsubscript{t+1}" ///
				incdiff2 "Inc. Shock\textsubscript{t0}" ///
				L.incdiff2 "Inc. Shock\textsubscript{t-1}" ///
				L2.incdiff2 "Inc. Shock\textsubscript{t-2}" ///
				L3.incdiff2 "Inc. Shock\textsubscript{t-3}" ///
				F.incdiff2 "Inc. Shock\textsubscript{t+1}" ///
				jobloss "Job loss\textsubscript{t0}" ///
				L.jobloss "Job loss\textsubscript{t-1}" ///
				L2.jobloss "Job loss\textsubscript{t-2}" ///
				L3.jobloss "Job loss\textsubscript{t-3}" ///
				F.jobloss "Job loss\textsubscript{t+1}" ///
				_cons "Constant")      

	
* FE models with differentation in terms of initial income deciles
foreach var of varlist polsup polint10 {	
	xtreg `var' L(0).idc1 L(0).idc2 L(0).idc3 L(0).idc4 L(0).idc5 age18 unemployed nlf edu_med edu_high, fe
	eststo fe_`var'_deccat
}
esttab fe_polsup_deccat fe_polint10_deccat ///
	using "$OUT\Tables\BHPS\fe_lag_all_deccat.rtf", b(3) se replace	
esttab fe_polsup_deccat fe_polint10_deccat ///
	using "$OUT\Tables\BHPS\fe_lag_all_deccat.tex", b(3) scalars("N N") se replace label nonumbers booktabs alignment(D{.}{.}{3})	///
	varlabels ///
				(edu_med "Edu: medium" ///
				edu_high "Edu: high" ///
				age18 "Age" ///
				unemployed "Unemployed" ///
				nlf "Not in Labor Force" ///
				hhinc "Income\textsubscript{t0}" ///
				L.hhinc "Income\textsubscript{t-1}" ///
				L2.hhinc "Income\textsubscript{t-2}" ///
				L3.hhinc "Income\textsubscript{t-3}" ///
				F.hhinc "Income\textsubscript{t+1}" ///
				hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t0}" ///
				L.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-1}" ///
				L2.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-2}" ///
				L3.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-3}" ///
				F.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t+1}" ///
				hhinc_sat "Sat. Income\textsubscript{t0}" ///
				L.hhinc_sat "Sat. Income\textsubscript{t-1}" ///
				L2.hhinc_sat "Sat. Income\textsubscript{t-2}" ///
				L3.hhinc_sat "Sat. Income\textsubscript{t-3}" ///
				F.hhinc_sat "Sat. Income\textsubscript{t+1}" ///
				incdiff2 "Inc. Shock\textsubscript{t0}" ///
				L.incdiff2 "Inc. Shock\textsubscript{t-1}" ///
				L2.incdiff2 "Inc. Shock\textsubscript{t-2}" ///
				L3.incdiff2 "Inc. Shock\textsubscript{t-3}" ///
				F.incdiff2 "Inc. Shock\textsubscript{t+1}" ///
				_cons "Constant")   
	
	
* FE models controlling for PI in t-2
xtreg polsup L2.polint incdiff2 age18 unemployed nlf edu_med edu_high, fe
eststo fe_polsup_polint_t2
xtreg polsup L2.polint incdiff2 age18 unemployed nlf edu_med edu_high pit2Xshock, fe
eststo fe_polsup_polint_t2_ia

esttab fe_polsup_polint_t2 fe_polsup_polint_t2_ia using "$OUT\Tables\BHPS\fe_polsup_polint-t2.rtf", b(3) se replace	nonumbers
esttab fe_polsup_polint_t2 fe_polsup_polint_t2_ia using "$OUT\Tables\BHPS\fe_polsup_polint-t2.tex", b(3) scalars("N N") se replace label nonumbers booktabs alignment(D{.}{.}{3})	///
	varlabels ///
				(edu_med "Edu: medium" ///
				edu_high "Edu: high" ///
				age18 "Age" ///
				unemployed "Unemployed" ///
				nlf "Not in Labor Force" ///
				hhinc "Income\textsubscript{t0}" ///
				L.hhinc "Income\textsubscript{t-1}" ///
				L2.hhinc "Income\textsubscript{t-2}" ///
				L3.hhinc "Income\textsubscript{t-3}" ///
				F.hhinc "Income\textsubscript{t+1}" ///
				hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t0}" ///
				L.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-1}" ///
				L2.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-2}" ///
				L3.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t-3}" ///
				F.hhinc_dec_pp_sqrt10 "Income (dec.)\textsubscript{t+1}" ///
				hhinc_sat "Sat. Income\textsubscript{t0}" ///
				L.hhinc_sat "Sat. Income\textsubscript{t-1}" ///
				L2.hhinc_sat "Sat. Income\textsubscript{t-2}" ///
				L3.hhinc_sat "Sat. Income\textsubscript{t-3}" ///
				F.hhinc_sat "Sat. Income\textsubscript{t+1}" ///
				incdiff2 "Inc. Shock\textsubscript{t0}" ///
				L.incdiff2 "Inc. Shock\textsubscript{t-1}" ///
				L2.incdiff2 "Inc. Shock\textsubscript{t-2}" ///
				L3.incdiff2 "Inc. Shock\textsubscript{t-3}" ///
				F.incdiff2 "Inc. Shock\textsubscript{t+1}" ///
				_cons "Constant")  
	
	
*Cross-check: objective income on subjective income 
foreach var of varlist hhinc hhinc_dec_pp_sqrt10 incdiff2 {
	xtreg hhinc_sat10 L(0/3).`var' F1.`var' age18 unemployed nlf edu_med edu_high, fe
	eststo m_`var'
	*regsave F1.`var' `var' L1.`var' L2.`var' L3.`var' using "$OUT2\BHPS\bhps_coef_lag_inc_subj_obj_`var'.dta", ci level(95) autoid append
}
esttab m_hhinc m_hhinc_dec_pp_sqrt10 m_incdiff2   ///
	using "$OUT\Tables\BHPS\fe_lag_all_inc_subj_obj.rtf", b(3) se replace			
esttab m_hhinc m_hhinc_dec_pp_sqrt10 m_incdiff2   ///
	using "$OUT\Tables\BHPS\fe_lag_all_inc_subj_obj.tex", b(3) se replace label nonumbers booktabs alignment(D{.}{.}{3})       	
	
	
* Error correction model: lagged DV	
*xtabond2 n L.polint10 L2.polint10 hhinc_dec10 age18 unemployed nlf edu_med edu_high, gmm(L.polint10) iv(hhinc_dec10) nolevel robust

foreach var of varlist polsup polint10  {
	// exogenous
	xtdpdsys `var' hhinc_dec_pp_sqrt10 age18 unemployed nlf edu_med edu_high, twostep vce(robust) lags(2) maxldep(2) maxlags(2) artests(2)
	estat abond
	eststo ec_exo_`var'_inc_pp_s
	
	// predetermined	
	xtdpdsys `var' age18 unemployed nlf edu_med edu_high, twostep vce(robust) lags(2) maxldep(2) maxlags(2) artests(2) pre(hhinc_dec_pp_sqrt10)
	estat abond
	eststo ec_pre_`var'_inc_pp_s
	
	// endogeneous
	xtdpdsys `var' age18 unemployed nlf edu_med edu_high, twostep vce(robust) lags(2) maxldep(2) maxlags(2) artests(2) end(hhinc_dec_pp_sqrt10)
	estat abond
	eststo ec_end_`var'_inc_pp_s
}


esttab ec_exo_polsup_inc_pp_s ec_pre_polsup_inc_pp_s ec_end_polsup_inc_pp_s ///
	ec_exo_polint10_inc_pp_s ec_pre_polint10_inc_pp_s ec_end_polint10_inc_pp_s ///
	using "$OUT\Tables\BHPS\ec_all_hhinc_dec_pp_sqrt.rtf", b(3) scalar(arm1 arm2) se replace
esttab ec_exo_polsup_inc_pp_s ec_pre_polsup_inc_pp_s ec_end_polsup_inc_pp_s ///
	ec_exo_polint10_inc_pp_s ec_pre_polint10_inc_pp_s ec_end_polint10_inc_pp_s ///
	using "$OUT\Tables\BHPS\ec_all_hhinc_dec_pp_sqrt.tex", b(3) scalar("N N" "arm1 ABT(1)" "arm2 ABT(1)") se replace label nonumbers booktabs alignment(D{.}{.}{3}) ///
	varlabels ///
				(edu_med "Edu: medium" ///
				edu_high "Edu: high" ///
				age18 "Age" ///
				unemployed "Unemployed" ///
				nlf "Not in Labor Force" ///
				hhinc "Income" ///
				hhinc_dec_pp_sqrt10 "Income (dec.)" ///
				hhinc_sat "Sat. Income" ///
				_cons "Constant" ///
				L.vote "Vote\textsubscript{t-1}" ///
				L2.vote "Vote\textsubscript{t-2}" ///
				L.polint "Pol. Interest\textsubscript{t-1}" ///
				L2.polint "Pol. Interest\textsubscript{t-2}" ///
				L.polls_times "No. polls\textsubscript{t-1}" ///
				L2.polls_times "No. polls\textsubscript{t-2}")    





	
	
	
	
	
	
	


